//
//  ApproveDetail.swift
//  DesignCode
//
//  Created by 李澄 on 2020/11/20.
//  Copyright © 2020 Mithun. All rights reserved.
//

import SwiftUI

struct ApproveDetail: View {
    var title = "审批详情"
    var image = "Illustration1"
    var applyId = ""
    @State var canEdit = false
    @State var date = ""
    @State var status = ""
    @State var isApproved = ""
    @State var suggestion = ""
    var personId = ""

    var body: some View {
       VStack(spacing: 20.0) {
          Text(title)
             .font(.largeTitle)
             .fontWeight(.heavy)
 
          Image(image)
             .resizable()
             .aspectRatio(contentMode: .fit)
             .frame(height: 200)
 
          Text("编号：\(applyId)")
              .lineLimit(1)
              .frame(minWidth: 0, maxWidth: .infinity, alignment:  .leading)
          Text("审批人编号：\(personId)")
              .lineLimit(1)
              .frame(minWidth: 0, maxWidth: .infinity, alignment:  .leading)
        HStack {
            Text("时间:")
                  .lineLimit(1)
                  .frame(alignment:  .leading)
            if canEdit {
                TextField("", text: $date)
            } else {
                Text(String(date))
                    .lineLimit(1)
                    .frame(maxWidth: .infinity, alignment:  .leading)
            }
                
        }
        HStack {
            Text("审批状态：")
                  .lineLimit(1)
                  .frame(alignment:  .leading)
            if canEdit {
                TextField("", text: $status)
            } else {
                Text(String(status))
                    .lineLimit(1)
                    .frame(maxWidth: .infinity, alignment:  .leading)
            }
                
        }
        HStack {
            Text("是否批准：")
                  .lineLimit(1)
                  .frame(alignment:  .leading)
            if canEdit {
                TextField("", text: $isApproved)
            } else {
                Text(String(isApproved))
                    .lineLimit(1)
                    .frame(maxWidth: .infinity, alignment:  .leading)
            }
                
        }
        HStack {
            Text("审批意见：")
                  .lineLimit(1)
                  .frame(alignment:  .leading)
            if canEdit {
                TextField("", text: $suggestion)
            } else {
                Text(String(suggestion))
                    .lineLimit(1)
                    .frame(maxWidth: .infinity, alignment:  .leading)
            }
                
        }
//          Spacer
//          VStack(spacing: 20.0) {
//            Text("申请人：\(personName)")
//               .lineLimit(1)
//               .frame(minWidth: 0, maxWidth: .infinity, alignment:  .leading)
//            Text("申请人编号：\(personId)")
//                .lineLimit(1)
//                .frame(minWidth: 0, maxWidth: .infinity, alignment:  .leading)
//            Text("申请状态：\(status)")
//                .lineLimit(1)
//                .frame(minWidth: 0, maxWidth: .infinity, alignment:  .leading)
//            
//          }

          Spacer()
        
        HStack(spacing: 20) {
            Button(action: edit) {
                CircleButton(icon: "pencil")
            }
            Button(action: approve) {
                CircleButton(icon: "person.fill.checkmark")
            }
            Button(action: approve) {
                CircleButton(icon: "delete.right")
            }
        }
       }
       .padding(30.0)
    }
    func edit() -> () {
        self.canEdit.toggle()
    }
    func approve() -> () {
        
    }
    func refuse() -> () {
        
    }
}

struct ApproveDetail_Previews: PreviewProvider {
    static var previews: some View {
        ApproveDetail()
    }
}
